<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="报价书编号" prop="quoteNum">
      <el-input v-model="dataForm.quoteNum" placeholder="报价书编号"></el-input>
    </el-form-item>
    <el-form-item label="询价书序号" prop="enquireId">
      <el-input v-model="dataForm.enquireId" placeholder="询价书序号"></el-input>
    </el-form-item>
    <el-form-item label="供应商序号" prop="supplierId">
      <el-input v-model="dataForm.supplierId" placeholder="供应商序号"></el-input>
    </el-form-item>
    <el-form-item label="报价单位" prop="quoCompany">
      <el-input v-model="dataForm.quoCompany" placeholder="报价单位"></el-input>
    </el-form-item>
    <el-form-item label="报价单位地址" prop="quoAddress">
      <el-input v-model="dataForm.quoAddress" placeholder="报价单位地址"></el-input>
    </el-form-item>
    <el-form-item label="报价单位联系人" prop="quoLinkman">
      <el-input v-model="dataForm.quoLinkman" placeholder="报价单位联系人"></el-input>
    </el-form-item>
    <el-form-item label="报价单位电话" prop="quoPhone">
      <el-input v-model="dataForm.quoPhone" placeholder="报价单位电话"></el-input>
    </el-form-item>
    <el-form-item label="报价单位传真" prop="quoFax">
      <el-input v-model="dataForm.quoFax" placeholder="报价单位传真"></el-input>
    </el-form-item>
    <el-form-item label="报价单位电子邮件" prop="quoEmail">
      <el-input v-model="dataForm.quoEmail" placeholder="报价单位电子邮件"></el-input>
    </el-form-item>
    <el-form-item label="报价书标题" prop="queTitle">
      <el-input v-model="dataForm.queTitle" placeholder="报价书标题"></el-input>
    </el-form-item>
    <el-form-item label="报价时间" prop="queDate">
<!--      <el-input v-model="dataForm.queDate" placeholder="报价时间"></el-input>-->
      <el-date-picker
        v-model="dataForm.queDate"
        type="date"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="询价截止时间" prop="endDate">
<!--      <el-input v-model="dataForm.endDate" placeholder="询价截止时间"></el-input>-->
      <el-date-picker
        v-model="dataForm.endDate"
        type="date"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="数量合计" prop="sumAmount">
      <el-input v-model="dataForm.sumAmount" placeholder="数量合计"></el-input>
    </el-form-item>
    <el-form-item label="总金额(元)" prop="overallPrice">
      <el-input v-model="dataForm.overallPrice" placeholder="总金额(元)"></el-input>
    </el-form-item>
    <el-form-item label="报价说明" prop="quoRemark">
      <el-input v-model="dataForm.quoRemark" placeholder="报价说明"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <el-select v-model="dataForm.procurementType" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.text"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          quoteNum: '',
          enquireId: '',
          supplierId: '',
          quoCompany: '',
          quoAddress: '',
          quoLinkman: '',
          quoPhone: '',
          quoFax: '',
          quoEmail: '',
          queTitle: '',
          queDate: '',
          endDate: '',
          sumAmount: '',
          overallPrice: '',
          quoRemark: '',
          status: '',
          procurementType:''
        },
        options: [
          { text: '公开求购', value: 'C000-1' },
          { text: '定向询价', value: 'C000-2' },
        ],
        dataRule: {
          quoteNum: [
            { required: true, message: '报价书编号不能为空', trigger: 'blur' }
          ],
          enquireId: [
            { required: true, message: '询价书序号不能为空', trigger: 'blur' }
          ],
          supplierId: [
            { required: true, message: '供应商序号不能为空', trigger: 'blur' }
          ],
          quoCompany: [
            { required: true, message: '报价单位不能为空', trigger: 'blur' }
          ],
          quoAddress: [
            { required: true, message: '报价单位地址不能为空', trigger: 'blur' }
          ],
          quoLinkman: [
            { required: true, message: '报价单位联系人不能为空', trigger: 'blur' }
          ],
          quoPhone: [
            { required: true, message: '报价单位电话不能为空', trigger: 'blur' }
          ],
          quoFax: [
            { required: true, message: '报价单位传真不能为空', trigger: 'blur' }
          ],
          quoEmail: [
            { required: true, message: '报价单位电子邮件不能为空', trigger: 'blur' }
          ],
          queTitle: [
            { required: true, message: '报价书标题不能为空', trigger: 'blur' }
          ],
          queDate: [
            // { required: true, message: '报价时间不能为空', trigger: 'blur' }
          ],
          endDate: [
            // { required: true, message: '询价截止时间不能为空', trigger: 'blur' }
          ],
          sumAmount: [
            { required: true, message: '数量合计不能为空', trigger: 'blur' }
          ],
          overallPrice: [
            { required: true, message: '总金额(元)不能为空', trigger: 'blur' }
          ],
          quoRemark: [
            { required: true, message: '报价说明不能为空', trigger: 'blur' }
          ],
          procurementType: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/purchase/quote/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then((data) => {
              if (data && data.code === 200) {
                this.dataForm.quoteNum = data.quote.quoteNum
                this.dataForm.enquireId = data.quote.enquireId
                this.dataForm.supplierId = data.quote.supplierId
                this.dataForm.quoCompany = data.quote.quoCompany
                this.dataForm.quoAddress = data.quote.quoAddress
                this.dataForm.quoLinkman = data.quote.quoLinkman
                this.dataForm.quoPhone = data.quote.quoPhone
                this.dataForm.quoFax = data.quote.quoFax
                this.dataForm.quoEmail = data.quote.quoEmail
                this.dataForm.queTitle = data.quote.queTitle
                this.dataForm.queDate = data.quote.queDate
                this.dataForm.endDate = data.quote.endDate
                this.dataForm.sumAmount = data.quote.sumAmount
                this.dataForm.overallPrice = data.quote.overallPrice
                this.dataForm.quoRemark = data.quote.quoRemark
                this.dataForm.procurementType = data.quote.procurementType
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/purchase/quote/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'quoteNum': this.dataForm.quoteNum,
                'enquireId': this.dataForm.enquireId,
                'supplierId': this.dataForm.supplierId,
                'quoCompany': this.dataForm.quoCompany,
                'quoAddress': this.dataForm.quoAddress,
                'quoLinkman': this.dataForm.quoLinkman,
                'quoPhone': this.dataForm.quoPhone,
                'quoFax': this.dataForm.quoFax,
                'quoEmail': this.dataForm.quoEmail,
                'queTitle': this.dataForm.queTitle,
                'queDate': this.dataForm.queDate,
                'endDate': this.dataForm.endDate,
                'sumAmount': this.dataForm.sumAmount,
                'overallPrice': this.dataForm.overallPrice,
                'quoRemark': this.dataForm.quoRemark,
                'procurementType': this.dataForm.procurementType
              })
            }).then((data) => {
              console.log(this.dataForm)
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
            console.log(this.data)
          }
        })
      }
    }
  }
</script>
